import Vue from "vue";
import axios from "axios";
import "./interceptors";

Vue.prototype.$axios = axios; //绑定axios到vue 实例上面
const Axios = axios;

export default {
  install(Vue) {
    Vue.prototype.allConfig = {
      baseURL: process.env.VUE_APP_MOCK_URL //区别正式测试环境，试验中
      //baseURL: "http://rap2api.taobao.org/app/mock/104575/ddechat/1"
    };
    Vue.prototype.$get = function (url, params, callback) { //get 请求
      let URL = this.allConfig.baseURL + url;
      Axios.get(URL, params)
         .then((result) => {
          callback(result)
        }).catch((error) => {
          console.log(error,'ddd')
        })
    };
    Vue.prototype.$post = function (url, params, callback) {  //post 请求
      let URL = this.allConfig.baseURL + url;
      Axios.post(URL, params)
        .then(( result ) => {
          callback(result)
        })
        .catch((error) => {
           console.log(error)
        })
      };
    Vue.prototype.$put = function (url, params, callback) {  //put 请求
      let URL = this.allConfig.baseURL + url;
      Axios.put(URL, params,)
        .then((result) => {
          callback(result);
        }).catch((error) => {
          console.log(error)
        })
      };









    }
}
